import 'package:flutter/material.dart';
import 'package:flutter_test_provider/gongxiang/provider_create.dart';
import 'package:flutter_test_provider/multiProviderDemo/userInfoProvider.dart';
import 'package:flutter_test_provider/provider_consumer/consumer_first_page.dart';
import 'package:flutter_test_provider/providerDemo/counter_provider.dart';
import 'package:flutter_test_provider/provider_of/provider_of.dart';

import 'package:provider/provider.dart';

import 'inheritedWidget/inherited_home_widget.dart';
import 'provider_selecter/selecter_first_page.dart';

// void main() {
//   runApp(ChangeNotifierProvider(
//     create: (context) => CounterProvider(),
//     child: MyApp(),
//   ));
// }

void main() {
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider(create: (ctx) => CounterProvider()),
      ChangeNotifierProvider(create: (ctx) => UserProvider()),
    ],
    child: MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List infoLsit = [
    "provider-creat",
    "provider-value",
    "ChangeNotifierProvider-create",
    "ChangeNotifierProvider-value",
    "MultiProvider",
    "proxyProvider",
    "InheritedWidget-demo",
    "provider.of-demo",
    "ProviderConsumer-demo",
    "ProviderConsumer2-demo",
    "ProviderSelector-demo",
    "ProviderSelector2-demo",
  ];

  @override
  Widget build(BuildContext context) {
    Widget divider = Divider(color: Colors.black);
    return Scaffold(
      appBar: AppBar(
        title: Text("InheritedWidget"),
      ),
      body: Center(
          child: ListView.separated(
              itemBuilder: (BuildContext context, int index) {
                return InkWell(
                  onTap: () {
                    pushToTargetPage(index);
                  },
                  child: Text(
                    infoLsit[index],
                    style: TextStyle(
                      fontSize: 17,
                    ),
                  ),
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return divider;
              },
              itemCount: infoLsit.length)),
    );
  }

  void pushToTargetPage(int index) {
    final String titleStr = infoLsit[index];
    if (titleStr == "provider-creat") {
      print("provider-creat");
      pushToProviderCreatePage();
    } else if (titleStr == "provider-value") {
    } else if (titleStr == "ChangeNotifierProvider-create") {
    } else if (titleStr == "ChangeNotifierProvider-value") {
    } else if (titleStr == "MultiProvider") {
    } else if (titleStr == "proxyProvider") {
    } else if (titleStr == "InheritedWidget-demo") {
      pushToHomeInheritedPage();
    } else if (titleStr == "provider.of-demo") {
      pushToProviderOfPage();
    } else if (titleStr == "ProviderConsumer-demo") {
      pushToConsumerFirstPage();
    } else if (titleStr == "ProviderConsumer2-demo") {
    } else if (titleStr == "ProviderSelector-demo") {
      pushToSelectorFirstPage();
    } else if (titleStr == "ProviderSelector2-demo") {

    }
  }

  
  void pushToProviderCreatePage() {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return ProviderCreatePage();
    }));
  }
  void pushToHomeInheritedPage() {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return LYHomeInteritedPage();
    }));
  }

  void pushToConsumerFirstPage() {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return ConsumerFirstPage();
    }));
  }

  void pushToSelectorFirstPage() {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return SelectorFirstPage();
    }));
  }

  void pushToProviderOfPage() {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return ProviderOfPage();
    }));
  }
}
